package com.huawei.appmarket.service.usercenter.userinfo.view.widget;

import android.content.Context;
import android.text.Editable;
import android.text.InputFilter;
import android.text.InputFilter.LengthFilter;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.LinearLayout;
import android.widget.Toast;
import com.huawei.appmarket.service.usercenter.userinfo.bean.UserInfoBean;
import huawei.widget.HwButton;
import huawei.widget.HwEditText;
import o.azb;
import o.der.d;
import o.der.f;
import o.der.g;
import o.dof;
import o.emj;
import o.emn;

public class MobilePhoneChangeView extends LinearLayout {
    protected UserInfoBean ʽ;
    protected TextWatcher ˊ;
    protected Context ˋ;
    protected HwEditText ˎ;
    OnCheckedChangeListener ˏ = new OnCheckedChangeListener(this) {
        final /* synthetic */ MobilePhoneChangeView ˊ;

        {
            this.ˊ = r1;
        }

        public void onCheckedChanged(CompoundButton compoundButton, boolean z) {
            if (this.ˊ.ॱ != null) {
                this.ˊ.ॱ.setEnabled(compoundButton.isChecked());
            }
        }
    };
    protected HwButton ॱ;
    protected emn ᐝ;

    protected void ˏ(String str) {
        if (dof.ˋ(str) || (ˋ() && !ॱ(str))) {
            Toast.makeText(this.ˋ, this.ˋ.getResources().getString(f.ˇ, new Object[]{Integer.valueOf(11)}), 0).show();
        } else if (this.ᐝ == null || this.ʽ == null) {
            Toast.makeText(this.ˋ, f.ᐝʼ, 0).show();
        } else {
            this.ʽ.ˊ(str);
            this.ᐝ.ˎ(this.ʽ);
        }
    }

    private boolean ॱ(String str) {
        return str.length() == 11 && emj.ˎ(str);
    }

    public MobilePhoneChangeView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.ˋ = context;
        ˊ();
    }

    public MobilePhoneChangeView(Context context) {
        super(context);
        this.ˋ = context;
        ˊ();
    }

    public void setInterfaceAndUserInfo(emn o_emn, UserInfoBean userInfoBean) {
        this.ᐝ = o_emn;
        this.ʽ = userInfoBean;
        if (this.ˎ != null) {
            this.ˎ.setHint(this.ˋ.getResources().getString(f.ꜟॱ, new Object[]{Integer.valueOf(11)}));
            this.ˎ.setFilters(new InputFilter[]{new LengthFilter(50)});
            this.ˎ.setInputType(3);
            if (this.ʽ != null && !dof.ˋ(this.ʽ.ॱ())) {
                this.ˎ.setText(emj.ˊ(this.ʽ.ॱ()));
                new emj(50).ॱ(this.ˎ, this.ˎ.getText().toString());
            }
        }
    }

    protected void ˊ() {
        View inflate = LayoutInflater.from(this.ˋ).inflate(g.ᐝˋ, this);
        this.ˎ = (HwEditText) inflate.findViewById(d.ᵔ);
        azb.ˋ(this.ˎ);
        CheckBox checkBox = (CheckBox) inflate.findViewById(d.ᶥ);
        azb.ˋ(checkBox);
        this.ॱ = (HwButton) inflate.findViewById(d.ᐝˋ);
        ॱ();
        checkBox.setOnCheckedChangeListener(this.ˏ);
        ˏ();
        this.ˎ.addTextChangedListener(this.ˊ);
    }

    protected void ˏ() {
        this.ˊ = new TextWatcher(this) {
            final /* synthetic */ MobilePhoneChangeView ˎ;

            {
                this.ˎ = r1;
            }

            public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            }

            public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
                this.ˎ.ˎ.setFilters(new InputFilter[]{new LengthFilter(11)});
            }

            public void afterTextChanged(Editable editable) {
            }
        };
    }

    protected void ॱ() {
        this.ॱ.setEnabled(false);
        this.ॱ.setOnClickListener(new OnClickListener(this) {
            final /* synthetic */ MobilePhoneChangeView ˋ;

            {
                this.ˋ = r1;
            }

            public void onClick(View view) {
                if (view == this.ˋ.ॱ) {
                    String obj;
                    if (this.ˋ.ˋ()) {
                        obj = this.ˋ.ˎ.getText().toString();
                    } else {
                        obj = this.ˋ.ʽ.ॱ();
                    }
                    this.ˋ.ˏ(obj);
                }
            }
        });
    }

    public boolean ˋ() {
        String str;
        if (this.ʽ == null || this.ʽ.ॱ() == null) {
            str = "";
        } else {
            str = ˋ(this.ʽ.ॱ());
        }
        return !str.equals(this.ˎ.getText().toString());
    }

    protected String ˋ(String str) {
        return emj.ˊ(str);
    }
}
